<?php

declare(strict_types=1);

namespace App\Service\Logic;

use App\Service\Business\UserRoleBusiness;
use App\Validator\CommonValidator;
use App\Validator\UserValidator;
use App\Validator\RoleValidator;
use Exception;
use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

/**
 * 用户角色-业务逻辑类
 */
class UserRoleLogic extends BaseLogic
{
        #[Inject]
        protected UserRoleBusiness $UserRoleBusiness;

        #[Inject]
        protected CommonValidator $CommonValidator;

        #[Inject]
        protected UserValidator $UserValidator;

        #[Inject]
        protected RoleValidator $RoleValidator;

        /**
         * 分页
         * @return array
         * @throws Exception
         */
        public function paginate(): array
        {
                $this->CommonValidator->validate($this->request->all(), ['page', 'limit']);
                return $this->UserRoleBusiness->paginate();
        }

        /**
         * 设定
         * @return array
         * @throws ContainerExceptionInterface
         * @throws NotFoundExceptionInterface
         * @throws Exception
         */
        public function setting(): array
        {
                $this->UserValidator->validate($this->request->all(), ['userId']);
                $this->RoleValidator->validate($this->request->all(), [], ['roleIds']);
                return $this->UserRoleBusiness->setting();
        }
}